<template>
  <div class="performanceResult-box">
    <nav-title title="绩效结果" :routerLink="routerLink"/>
    <div class="topTip">
      <span @click="()=>{year-=1;load = false;getData()}"><</span>
      <p>{{year}}年</p>
      <span @click="()=>{year+=1;load = false;getData()}">></span>
    </div>
    <div v-if="load && !list.length" class="noData">暂无数据</div>
    <div v-else-if="load" v-for="(item, index) in list" class="performanceResult-list" @click="()=>active = index">
      <h6>{{item.yearMonth}}</h6>
      <div class="performanceResult-list-row">
        <div class="label">考核模板</div>
        <div class="value">{{item.tempName}}</div>
      </div>
      <div class="performanceResult-list-row">
        <div class="label">排名组</div>
        <div class="value">{{item.groupName}}</div>
      </div>
      <div class="performanceResult-list-col-box">
        <div>
          <div class="label">绩效得分</div>
          <div class="value">{{item.score}}</div>
        </div>
        <div>
          <div class="label">排名</div>
          <div class="value">{{item.ranking}}</div>
        </div>
      </div>
      <div class="performanceResult-list-col-box">
        <div>
          <div class="label">绩效等级</div>
          <div class="value">{{item.level}}</div>
        </div>
        <div>
          <div class="label">绩效系数</div>
          <div class="value">{{item.rate}}</div>
        </div>
      </div>
      <div v-if="(active === index)" class="performanceResult-list-button">
        <button @click="interview">面 谈</button>
        <button @click="appeal">申 诉</button>
      </div>
    </div>
  </div>
</template>

<script>
import { getPerresultList } from "../../api/api";
import { Group, PopupRadio } from "vux";
import moment from 'moment';
export default {
  name: "PerformanceResult",
  components: {
    Group,
    PopupRadio,
  },
  created() {
    this.emplid = this.$route.query.emplid;
    this.year = moment(new Date()).format('YYYY')/1;
  },
  mounted() {
    this.getData();
  },
  data() {
    return {
      routerLink: '',
      emplid: '',
      year: '',
      active: '',
      load: false,
      list: [
        // {
        //   time: '2018年04月',
        //   tpl: '控股集团总部员工PPI考核模板',
        //   rankingGulp: '人力资源中心S级员工',
        //   score: '95',
        //   ranking: '1/2',
        //   grade: 'P7',
        //   coefficient: '0.7',
        // },
        // {
        //   time: '2018年04月',
        //   tpl: '控股集团总部员工PPI考核模板',
        //   rankingGulp: '人力资源中心S级员工',
        //   score: '95',
        //   ranking: '1/2',
        //   grade: 'P7',
        //   coefficient: '0.7',
        // }
      ],
    };
  },
  methods: {
    getData() {
      this.$vux.loading.show();
      let params = {
        year: this.year,
      };
      getPerresultList(params)
        .then(res => {
          this.load = true;
          this.$vux.loading.hide();
          if (res && res.retCode === "000000") {
            this.list = res.retData;
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.load = true;
          this.$vux.loading.hide();
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    interview() {
      this.$router.push({
        name: 'PerformanceInterview',
        query: {
          docid: this.list[this.active].docid,
          year: this.year,
          version: this.list[this.active].version,
          from: 'performanceResult'
        }
      })
    },
    appeal() {
      this.$router.push({
        name: 'PerformanceAppeal',
        query: {
          docid: this.list[this.active].docid,
          year: this.year,
          version: this.list[this.active].version,
          from: 'performanceResult'
        }
      })
    }
  }
};
</script>

<style type="text/scss" lang="scss">
  .performanceResult-box{
    padding-bottom: 20px;
    .noData{
      font-size: 20px;
      padding-top: 50px;
    }
    .topTip{
      background-color: #eee;
      position: relative;
      line-height: 36px;
      font-size: 20px;
      font-weight: bold;
      >span{
        position: absolute;
        top: 0;
        line-height: 36px;
        &:first-child{
          left: 20px;
        }
        &:last-child{
          right: 20px;
        }
      }
    }
    .performanceResult-list{
      border-bottom: 1px solid #ccc;
      padding: 10px;
      text-align: left;
      font-size: 16px;
      div{
        line-height: 2.0;
      }
      >h6{
        background-color: #ccc;
        display: inline-block;
        border-radius: 5px;
        padding: 4px 10px;
      }
      .performanceResult-list-row{
        width: 100%;
        display: flex;
        line-height: 32px;
        box-sizing: border-box;
        >div:first-child{
          // flex: 1;
          width: 90px;
          flex: none;
          text-align: right;
          display: inline-block;
        }
        >div:last-child{
          // flex: 2;
          width: 100%;
          display: inline-block;
          color: #999;
          padding-left: 20px;
          box-sizing: border-box;
        }
      }
      .performanceResult-list-col-box{
        width: 100%;
        display: flex;
        >div{
          flex: 1;
          >div:first-child{
            // flex: 2;
            width: 90px;
            display: inline-block;
            text-align: right;
          }
          >div:last-child{
            // flex: 1;
            display: inline-block;
            padding-left: 20px;
            color: #999;
          }
        }
      }
      .performanceResult-list-button{
        width: 100%;
        padding: 10px;
        text-align: center;
        >button{
          padding: 8px 20px;
          font-size: 16px;
          border-radius: 5px;
          color: #fff;
          font-weight: bold;
          margin: 0 20px;
        }
        >button:first-child{
          background-color: rgba(28, 170, 254, 1);
        }
        >button:last-child{
          background-color: rgba(255, 152, 0, 1);
        }
      }
    }
  }
</style>
